<?php
class jobsolution{
	protected $id,$job,$name,$value;

	function __construct($id,$jobid,$name,$value){
		$this->id = $id;
		$this->job = job::getJobById($jobid);		
		$this->name = $name;
		$this->value=$value;
	}
	
	public function getId(){
		return $this->id;
	}
	
	public function getJob(){
		return $this->job;	
	}
	
	public function getName(){
		return $this->name;	
	}
	
	public function getValue(){
		return $this->value;	
	}
	
	public static function getJobSolutionByJobId($id){
		$conn = new dbmodifier();
		$query = "SELECT * FROM jobsolution WHERE job_id='".$id."' ORDER BY value";
		$result = $conn->updateSQL($query);
		$conn->execute();
		return $result;
	}
	
	public static function getJobSolutionById($id){
		$conn = new dbmodifier();
		$id = $conn->db_connection->real_escape_string($id);
		$query = "SELECT * FROM jobsolution WHERE id='".$id."'";
		$result = $conn->updateSQL($query);
		$conn->execute();
		$row = $result->fetch_array(MYSQLI_ASSOC);
		$var = new jobsolution($row['id'],$row['job_id'],$row['name'],$row['value']);		
		return $var;	

	}
	
	public static function createJobSolution($job_id,$name,$value){
		$conn = new dbmodifier();
		$job_id = $conn->db_connection->real_escape_string($job_id);
		$name = $conn->db_connection->real_escape_string($name);
		$value = $conn->db_connection->real_escape_string($value);
		$query = "INSERT INTO jobsolution (job_id,name,value) " .
				 " VALUES ('".$job_id."','".$name."','".$value."')";
		$id = $conn->updateSQLKey($query);
		$conn->execute();
		$var = new jobsolution($id,$job_id,$name,$value);
		return $var;	
	}	
	
	public static function deleteJobSolutionByJobId($id){
		$conn = new dbmodifier();
		$query = "DELETE FROM jobsolution WHERE job_id=".$id;
		$result = $conn->updateSQL($query);
		$conn->execute();
		return $result;	
	}
}
?>
